<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="编号" prop="id">
        <el-input
            v-model="queryParams.id"
            placeholder="请输入编号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="集中度" prop="holdFocus">-->
<!--        <el-select v-model="queryParams.holdFocus" placeholder="请选择集中度" clearable>-->
<!--          <el-option-->
<!--              v-for="dict in com_hold_focus"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="人均持股" prop="peopleAvgHoldShares">-->
<!--        <el-input-->
<!--            v-model="queryParams.peopleAvgHoldShares"-->
<!--            placeholder="请输入人均持股"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="代码" prop="stockCode">
        <el-input
            v-model="queryParams.stockCode"
            placeholder="请输入代码"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名字" prop="stockName">
        <el-input
            v-model="queryParams.stockName"
            placeholder="请输入名字"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司类型" prop="companyType">
        <el-input
            v-model="queryParams.companyType"
            placeholder="请输入公司类型"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司简介" prop="companyUrl">
        <el-input
            v-model="queryParams.companyUrl"
            placeholder="请输入公司简介"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="处理状态" prop="done">-->
<!--        <el-input-->
<!--            v-model="queryParams.done"-->
<!--            placeholder="请输入处理状态"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="流通股东持股" prop="freeholdRatioTotal">-->
<!--        <el-input-->
<!--            v-model="queryParams.freeholdRatioTotal"-->
<!--            placeholder="请输入流通股东持股"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="" prop="datetime">-->
<!--        <el-input-->
<!--            v-model="queryParams.datetime"-->
<!--            placeholder="请输入"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="统计日期" prop="endDate">-->
<!--        <el-input-->
<!--            v-model="queryParams.endDate"-->
<!--            placeholder="请输入统计日期"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="股东人数" prop="holderTotalNum">-->
<!--        <el-input-->
<!--            v-model="queryParams.holderTotalNum"-->
<!--            placeholder="请输入股东人数"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="均价" prop="priceAve">-->
<!--        <el-input-->
<!--            v-model="queryParams.priceAve"-->
<!--            placeholder="请输入均价"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="十大股东持股" prop="holdRatioTotal">-->
<!--        <el-input-->
<!--            v-model="queryParams.holdRatioTotal"-->
<!--            placeholder="请输入十大股东持股"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="人数较上期变化" prop="totalNumRatio">-->
<!--        <el-input-->
<!--            v-model="queryParams.totalNumRatio"-->
<!--            placeholder="请输入人数较上期变化"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['enterprise:profile:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['enterprise:profile:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['enterprise:profile:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['enterprise:profile:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="profileList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" min-width="5%"/>
      <el-table-column label="编号" align="center" prop="id" min-width="5%"/>
<!--      <el-table-column label="集中度" align="center" prop="holdFocus" min-width="5%">-->
<!--        <template #default="scope">-->
<!--          <dict-tag :options="com_hold_focus" :value="scope.row.holdFocus"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="人均持股" align="center" prop="peopleAvgHoldShares" min-width="5%"/>-->
      <el-table-column label="代码" align="center" prop="stockCode" min-width="10%"/>
      <el-table-column label="名字" align="center" prop="stockName" min-width="10%"/>
      <el-table-column label="核心题材" align="center" prop="tcName" min-width="25%"/>
      <el-table-column label="入选原因" align="center" prop="selectedBoardReason" min-width="15%"/>
<!--      <el-table-column label="公司类型" align="center" prop="companyType" min-width="5%"/>-->
      <el-table-column label="公司简介" align="center" prop="companyUrl" min-width="10%"/>
<!--      <el-table-column label="处理状态" align="center" prop="done" min-width="5%"/>-->
      <el-table-column label="公司名字" align="center" prop="companyName" min-width="15%"/>
      <el-table-column label="主营业务" align="center" prop="mainBusiness" min-width="25%"/>
<!--      <el-table-column label="流通股东持股" align="center" prop="freeholdRatioTotal" min-width="5%"/>-->
<!--      <el-table-column label="" align="center" prop="datetime" min-width="5%"/>-->
<!--      <el-table-column label="统计日期" align="center" prop="endDate" min-width="5%"/>-->
<!--      <el-table-column label="股东人数" align="center" prop="holderTotalNum" min-width="5%"/>-->
<!--      <el-table-column label="均价" align="center" prop="priceAve" min-width="5%"/>-->
<!--      <el-table-column label="十大股东持股" align="center" prop="holdRatioTotal" min-width="5%"/>-->
<!--      <el-table-column label="人数较上期变化" align="center" prop="totalNumRatio" min-width="5%"/>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="10%">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['enterprise:profile:edit']">修改
          </el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['enterprise:profile:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改公司信息对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="profileRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="集中度" prop="holdFocus">
          <el-select v-model="form.holdFocus" placeholder="请选择集中度">
            <el-option
                v-for="dict in com_hold_focus"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="人均持股" prop="peopleAvgHoldShares">
          <el-input v-model="form.peopleAvgHoldShares" placeholder="请输入人均持股"/>
        </el-form-item>
        <el-form-item label="代码" prop="stockCode">
          <el-input v-model="form.stockCode" placeholder="请输入代码"/>
        </el-form-item>
        <el-form-item label="名字" prop="stockName">
          <el-input v-model="form.stockName" placeholder="请输入名字"/>
        </el-form-item>
        <el-form-item label="核心题材" prop="tcName">
          <el-input v-model="form.tcName" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="入选原因" prop="selectedBoardReason">
          <el-input v-model="form.selectedBoardReason" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="公司类型" prop="companyType">
          <el-input v-model="form.companyType" placeholder="请输入公司类型"/>
        </el-form-item>
        <el-form-item label="公司简介" prop="companyUrl">
          <el-input v-model="form.companyUrl" placeholder="请输入公司简介"/>
        </el-form-item>
        <el-form-item label="处理状态" prop="done">
          <el-input v-model="form.done" placeholder="请输入处理状态"/>
        </el-form-item>
        <el-form-item label="公司名字" prop="companyName">
          <el-input v-model="form.companyName" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="主营业务" prop="mainBusiness">
          <el-input v-model="form.mainBusiness" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="流通股东持股" prop="freeholdRatioTotal">
          <el-input v-model="form.freeholdRatioTotal" placeholder="请输入流通股东持股"/>
        </el-form-item>
        <el-form-item label="" prop="datetime">
          <el-input v-model="form.datetime" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="统计日期" prop="endDate">
          <el-input v-model="form.endDate" placeholder="请输入统计日期"/>
        </el-form-item>
        <el-form-item label="股东人数" prop="holderTotalNum">
          <el-input v-model="form.holderTotalNum" placeholder="请输入股东人数"/>
        </el-form-item>
        <el-form-item label="均价" prop="priceAve">
          <el-input v-model="form.priceAve" placeholder="请输入均价"/>
        </el-form-item>
        <el-form-item label="十大股东持股" prop="holdRatioTotal">
          <el-input v-model="form.holdRatioTotal" placeholder="请输入十大股东持股"/>
        </el-form-item>
        <el-form-item label="人数较上期变化" prop="totalNumRatio">
          <el-input v-model="form.totalNumRatio" placeholder="请输入人数较上期变化"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Profile">
import {listProfile, getProfile, delProfile, addProfile, updateProfile} from "@/api/enterprise/profile";

const {proxy} = getCurrentInstance();
const {com_hold_focus} = proxy.useDict('com_hold_focus');

const profileList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    id: null,
    holdFocus: null,
    peopleAvgHoldShares: null,
    stockCode: null,
    stockName: null,
    tcName: null,
    selectedBoardReason: null,
    companyType: null,
    companyUrl: null,
    done: null,
    companyName: null,
    mainBusiness: null,
    freeholdRatioTotal: null,
    datetime: null,
    endDate: null,
    holderTotalNum: null,
    priceAve: null,
    holdRatioTotal: null,
    totalNumRatio: null,
  },
  rules: {
    updateTime: [
      {required: true, message: "更新时间不能为空", trigger: "blur"}
    ]
  }
});

const {queryParams, form, rules} = toRefs(data);

/** 查询公司信息列表 */
function getList() {
  loading.value = true;
  listProfile(queryParams.value).then(response => {
    profileList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    holdFocus: null,
    peopleAvgHoldShares: null,
    stockCode: null,
    stockName: null,
    tcName: null,
    selectedBoardReason: null,
    companyType: null,
    companyUrl: null,
    done: null,
    companyName: null,
    mainBusiness: null,
    freeholdRatioTotal: null,
    datetime: null,
    endDate: null,
    holderTotalNum: null,
    priceAve: null,
    holdRatioTotal: null,
    totalNumRatio: null,
    updateTime: null
  };
  proxy.resetForm("profileRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加公司信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getProfile(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改公司信息";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["profileRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateProfile(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addProfile(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除公司信息编号为"' + _ids + '"的数据项？').then(function () {
    return delProfile(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
  });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('enterprise/profile/export', {
    ...queryParams.value
  }, `profile_${new Date().getTime()}.xlsx`)
}

getList();
</script>
